clear
clear matrix
clear mata
set more off, perm
set matsize 11000
set maxvar 30000
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/
global output /Users/zachbrown/Projects/PriceTransparency/Output

// open visit dataset
use clean/radiology_visit_3.dta, clear


egen prov_proc_fe = group(proc_id_radio prov_id payer_id)


// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)
label var web_post "$\text{OnWeb}\textsubscript{j}\times\text{Post}\textsubscript{t}$"


gen web_post_sr= web_post
replace web_post_sr = 0 if ym>ym(2009,3)
gen web_post_lr= web_post
replace web_post_lr = 0 if ym<=ym(2009,3)

gen in_nh_post = (prov_in_nh==1 & post==1)
label var in_nh_post "$\text{InNH}\textsubscript{j}\times\text{Post}\textsubscript{t}$"

gen in_nh_post_sr= in_nh_post
replace in_nh_post_sr = 0 if ym>ym(2009,3)
gen in_nh_post_lr= in_nh_post
replace in_nh_post_lr = 0 if ym<=ym(2009,3)
label var in_nh_post_sr "$\text{InNH}\textsubscript{j}\times\text{PostShortRun}\textsubscript{t}$"
label var in_nh_post_lr "$\text{InNH}\textsubscript{j}\times\text{PostLongRun}\textsubscript{t}$"


global ctr_vars = "age male i.charlindex zip_mean_income zip_pct_ba"


reghdfe ln_amt_allowed in_nh_post_sr in_nh_post_lr $ctr_vars if visit_on_web==1, absorb(prov_proc_fe ym std_product_type) vce(cl ym)
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a1


reghdfe ln_amt_allowed_radio in_nh_post_sr in_nh_post_lr $ctr_vars if visit_on_web==1, absorb(prov_proc_fe ym std_product_type) vce(cl ym)
summ amt_allowed_radio if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a2


esttab a1 a2 using $output/supply_side_regs_outsidenh_a.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(in_nh_post_sr in_nh_post_lr )  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 

esttab a1 a2 using $output/supply_side_regs_outsidenh_b.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp r2_a N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 

